package vns.server;

import vns.shared.AccountData;

import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

public class Google_Login {

 public AccountData getLoginData(String currentUrl) {
    
    UserService userService = UserServiceFactory.getUserService();
    
    String loginUrl = userService.createLoginURL(currentUrl);
    String logoutUrl = userService.createLogoutURL(currentUrl);
    
    User u = userService.getCurrentUser();
    String userId = null;
    String nick = null;
    String email = null;
    boolean isAdmin = false;
    boolean isLoggedIn = false;
    if (u != null) {
      userId = u.getUserId();
      nick = u.getNickname();
      email = u.getEmail();
      isLoggedIn = userService.isUserLoggedIn();
      isAdmin = userService.isUserAdmin();
    }
    
    AccountData accountData = new AccountData();
    accountData.setGoogleLoginUrl(loginUrl);
    accountData.setGoogleLogoutUrl(logoutUrl);
    accountData.setGoogleUserId(userId);
    accountData.setGoogleNick(nick);
    accountData.setGoogleEmail(email);
    accountData.setGoogleLoggedIn(isLoggedIn);
    accountData.setGoogleAdmin(isAdmin);
    
    return accountData;
  }
  
}
